package com.lmpop.frame;

import com.lmpop.frame.dao.DbmInterf;
import com.lmpop.frame.dao.IbatisDbmImpl;
import com.lmpop.frame.util.Config;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class QueryList
{
  private Config config;
  private DbmInterf dbmMgr;

  public QueryList()
  {
    this.config = new Config();
    this.config.init("config.properties");
    this.dbmMgr = IbatisDbmImpl.getInstance();
  }

  public synchronized List getList(String arg1)
  {
    return getList(arg1, null);
  }

  public synchronized void executeSql(String arg1, Object arg2) {
    this.dbmMgr.updateSql(arg1, arg2);
  }

  public synchronized List getList(String arg1, Object arg2) {
    List listrst = this.dbmMgr.getList(arg1, arg2);
    List rstlist = new ArrayList();
    if (listrst == null) return null;
    if ((listrst != null) && (listrst.size() > 0))
    {
      for (int i = 0; i < listrst.size(); i++)
      {
        HashMap map = (HashMap)listrst.get(i);
        Map rstmap = new Hashtable();
        Set mapSet = map.keySet();
        Iterator itor = mapSet.iterator();
        while (itor.hasNext()) {
          String skey = (String)itor.next();
          if (map.get(skey) != null)
          {
            rstmap.put(skey, map.get(skey).toString());
          }
          else
          {
            rstmap.put(skey, "");
          }
        }
        rstlist.add(rstmap);
      }
    }

    return rstlist;
  }

  public synchronized Map getObject(String arg1, Object arg2) {
    List list = getList(arg1, arg2);
    Map map = new Hashtable();
    if ((list != null) && (list.size() > 0)) {
      map = (Hashtable)list.get(0);
    }
    return map;
  }
}